package com.pan.aop;

import com.pan.anno.MyController;
import com.pan.anno.MyRequestMapping;
import com.pan.anno.PutYouHere;
import com.pan.mvc.*;
import com.pan.seed.User;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2020/11/24
 */
@MyController
public class UserController {


    private IUserService userService =new UserService();


    /**
     * 用户列表
     *
     * @return
     */
    @MyRequestMapping(value = "/user-all", method = RequestMethod.GET)
    public void getAllUser() {
        List<User> userList = userService.getAllUserWithoutDB();
        System.out.println("userList:"+userList.toString());
    }

    /**
     * 用户列表
     *
     * @return
     */
    @MyRequestMapping(value = "/userList", method = RequestMethod.GET)
    public View getUserList() {
        List<User> userList = userService.getAllUser();
        return new View("index.jsp").addModel("userList", userList);
    }

    /**
     * 用户详情
     *
     * @param param
     * @return
     */
    @MyRequestMapping(value = "/userInfo", method = RequestMethod.GET)
    public Data getUserInfo(Param param) {
        String id = (String) param.getParamMap().get("id");
        User user = userService.GetUserInfoById(Integer.parseInt(id));

        return new Data(user);
    }

    @MyRequestMapping(value = "/userEdit", method = RequestMethod.GET)
    public Data editUser(Param param) {
        String id = (String) param.getParamMap().get("id");
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("age", 911);
        userService.updateUser(Integer.parseInt(id), fieldMap);

        return new Data("Success.");
    }
}
